package com.quyunshuo.module.home.fragment.home

import android.util.Log
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.quyunshuo.edwingoal.base.utils.BarUtils
import com.quyunshuo.edwingoal.common.ui.BaseFragment
import com.quyunshuo.module.home.activity.main.SharedViewModel
import com.quyunshuo.module.home.activity.report.ReportActivity
import com.quyunshuo.module.home.databinding.HomeFragmentHomeBinding
import com.quyunshuo.module.home.fragment.compose.HomePage
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

/**
 * @author DBoy 2021/7/6 <p>
 * - 文件描述 : 测试fragment
 */
@AndroidEntryPoint
class HomeFragment : BaseFragment<HomeFragmentHomeBinding, SharedViewModel>() {
    private val TAG = "HomeFragment"

    //    override val mViewModel by viewModels<HomeViewModel>()
    override fun createVB() = HomeFragmentHomeBinding.inflate(layoutInflater)
    override val mViewModel: SharedViewModel by activityViewModels()


    override fun HomeFragmentHomeBinding.initListener() {
        stepCount.setOnClickListener {
            ReportActivity.newInstance(requireContext())
        }

    }

    override fun HomeFragmentHomeBinding.initView() {
        BarUtils.setStatusBarLightMode(requireActivity(), false)
        composeView.setContent {
            HomePage{
                Log.d(TAG, "initView:HomePage ")
            }
        }

    }

    override fun onDestroyView() {
        super.onDestroyView()
    }

    override fun initObserve() {
        lifecycleScope.launch {
            repeatOnLifecycle(Lifecycle.State.STARTED){
                mViewModel.stepCount.collect{
                    mBinding.stepCount.text = it.toString()
                    mBinding.progressBar.setProgress(((it.toFloat()?:0f)/50000)*100)//50000目标值。
                }
            }
        }


    }

    override fun initRequestData() {
    }


}